<?php $this->_extends('../_layouts/default_layout'); ?>
<?php $this->_block('contents'); ?>
<link type="text/css" href="<?=Q::ini('custom_system/base_url')?>css/jq.mselect.css" rel="stylesheet" />
<link type="text/css" href="<?=Q::ini('custom_system/base_url')?>css/prettyphoto.css" rel="stylesheet" />
<script type="text/javascript" src="<?=Q::ini('custom_system/base_url')?>js/jq.prettyphoto.js"></script>
<script type="text/javascript" src="<?=Q::ini('custom_system/base_url')?>js/jq.multiselect.js"></script>
<style>.unseen_input{border:none;}</style>
<script type="text/javascript">
$(function(){
	$("a[rel^='pretty_photo']").prettyPhoto({theme:'facebook'});
	$(".datepicker").datepicker({dateFormat:'yy-mm-dd',changeMonth:true});
	$(".info").colorbox({width:"80%", height:"70%", iframe:true});
	$(".edit").colorbox({width:"50%", height:"40%", iframe:true});
	$(".detect").colorbox({width:"50%", height:"80%", iframe:true});
	$("#multiselect").multiselect({height: 260, minWidth: 160});
	$(".bulkedit").colorbox({width:"50%", height:"80%", iframe:true});
	var transaction_id;
	$("#dialog_refund_transaction_id").dialog({autoOpen:false,modal:true});
	$("#dialog_refund_audit_ids").dialog({autoOpen:false,modal:true});
	$(".addrefund_click").click(function(){
		$("#refund_transaction_ids").val($(this).next().val());
		$("#refund_value").val($(this).next().next().val());
		$("#dialog_refund_transaction_id").dialog("open");
	});
	$("#request_download").click(function(){
		var current_tag = $(this);
		$(this).attr("disabled", true);
		var url_arr = current_tag.prev().val();
		$.ajax({
			url: "<?=url('Finance::Business/RefundDownload')?>&url_arr_json=" + url_arr,
			type: "get",
			dataType: "json",
			success:
				function(ret)
				{
					if (ret['ack'] == 'success')
					{
						current_tag.parent().append("<a href='"+ret['url']+"'>下载文件</a>");
					}
					else
					{
						current_tag.parent().append("请求失败");
					}
				}
		})
	});
	$("#audit_btn").click(function(){
		if ( ! confirm("确定批量审核？"))
		{
			return false;
		}
		var ids = new Array();
		$(".list_table").find("input[type='checkbox']").each(function(){
			if ($(this).is(":checked"))
			{
				ids.push($(this).val());
			}
		});
		if (ids.length == 0)
		{
			alert("请选择订单");
			return false;
		}
		$("#dialog_refund_audit_ids").dialog("open");
		$("#ids").val(ids);
	});
	$("#check_all").click(function(){
		if ($(this).is(":checked"))
		{
			$(".list_table input[type='checkbox']:enabled").attr("checked", true);
		}
		else
		{
			$(".list_table input[type='checkbox']:enabled").attr("checked", false);
		}
	});
})
</script>
<fieldset><legend>查询条件</legend>
<form method="get">
<? include(Q::ini('custom_system/elements_dir') . 'searchform_element.php');?>
<table class="form_table" width="80%">
<tr>
	<th width="100">退款日期</th>
	<td>
		<input type="text" name="begin_refund_time" class="datepicker" value="<?=isset($_GET['begin_refund_time']) ? $_GET['begin_refund_time'] : ''?>" /> to
		<input type="text" name="end_refund_time" class="datepicker" value="<?=isset($_GET['end_refund_time']) ? $_GET['end_refund_time'] : ''?>" />
	</td>
	<th>网站/店铺</th>
	<td>
		<select name="shop_id[]" multiple="multiple" id="multiselect">
		<?foreach ($shop_group as $k => $sg):?>
		<optgroup label="<?=$k?>">
		<?foreach ($sg as $s):?>
		<option value="<?=$s['id']?>" <?if (isset($_GET['shop_id']) && is_array($_GET['shop_id']) && in_array($s['id'], $_GET['shop_id'])) echo "selected='selected'"?>><?=$s['name']?></option>
		<?endforeach;?>
		</optgroup>
		<?endforeach;?>
		</select>
	</td>
</tr>
<tr>
	<th>退款单号</th>
	<td><input type="text" name="number" value="<?=isset($_GET['number']) ? $_GET['number'] : ''?>" /></td>
	<th>类型</th>
	<td>
		<select name="type">
			<option value="">请选择..</option>
			<option value="1" <?if (isset($_GET['type']) && $_GET['type'] == 1) echo "selected='selected'"?>>+</option>
			<option value="-1" <?if (isset($_GET['type']) && $_GET['type'] == -1) echo "selected='selected'"?>>-</option>
		</select>
	</td>
</tr>
<tr>
	<th>退款交易号</th>
	<td><input type="text" name="refund_transaction_id" value="<?=isset($_GET['refund_transaction_id']) ? $_GET['refund_transaction_id'] : ''?>" /></td>
	<th>退款原因</th>
	<td>
		<select name="reason">
			<option value="">请选择..</option>
			<?foreach (Q::ini('custom_flag/sales_refund_reason') as $s):?>
			<option value="<?=$s['value']?>" <?if(isset($_GET['reason']) && $_GET['reason']==$s['value'])echo "selected='selected'"?>><?=$s['name']?></option>
			<?endforeach;?>
		</select>
	</td>
</tr>
<tr>
	<th>状态</th>
	<td colspan="3">
		<label><input type="checkbox" name="refund_status[1]" value="1" <?if (isset($_GET['refund_status'][1]))echo "checked='checked'"?> /> 财务未确认</label>
		<label><input type="checkbox" name="refund_status[2]" value="2" <?if (isset($_GET['refund_status'][2]))echo "checked='checked'"?> /> 财务已确认</label>
	</td>
</tr>
<tr>
	<th>发货状态</th>
	<td colspan="3">
		<label><input type="checkbox" name="shipping_status[0]" value="0" <?if (isset($_GET['shipping_status'][0]))echo "checked='checked'"?> /> 未发</label>
		<label><input type="checkbox" name="shipping_status[1]" value="1" <?if (isset($_GET['shipping_status'][1]))echo "checked='checked'"?> /> 已发</label>
	</td>
</tr>
<tr>
	<th></th>
	<td>
		<input type="hidden" name="is_search" value="1" />
		<input type="submit" class="button" value="查询" />
	</td>
	<th></th>
	<td>
		<?if (isset($url_arr)):?>
		<input type="hidden" value='<?=json_encode($url_arr)?>' />
		<input type="button" class="button" value="请求下载" id="request_download" />
		<?endif;?>
	</td>
</tr>
</table>
</form>
</fieldset>
<table width="100%" class="list_table">
<tr>
	<th></th>
	<th width="120">退款日期</th>
	<th width="120">网站/店铺</th>
	<th width="100">退款单号</th>
	<th width="80">金额</th>
	<th width="60">退款方式</th>
	<th>退款账号</th>
	<th width="120">收款交易号</th>
	<th width="120">退款交易号</th>
	<th width="120">退款原因</th>
	<th width="120">退款备注</th>
	<th width="80">发货状态</th>
	<th width="110">操作</th>
</tr>
<?foreach ($sales_refund as $sr):?>
<tr>
	<td><input type="checkbox" value="<?=$sr['id']?>" <?if ($sr['status'] == Q::ini('custom_flag/sales_refund_status/audited/value')):?>disabled="disabled"<?endif;?>/></td>
	<td><?=substr($sr['refund_time'], 0, 10)?></td>
	<td><?=$sr['shop_name']?></td>
	<td><a class="info" href="<?=url('Finance::Business/RefundInfo', array('id'=>$sr['id']))?>"><?=$sr['number']?></a></td>
	<td><?=($sr['type']==1)?'+':'-'?><?=$sr['currency_symbol'] . sprintf('%.2f', $sr['refund_amount'])?></td>
	<td><?=Helper_BSS_Normal::getIniOne('sales_order_payment_method', 'value', $sr['refund_method'], 'name')?></td>
	<td><?=$sr['refund_account']?></td>
	<td><?=isset($sr['receive_transaction_id']) ? $sr['receive_transaction_id'] : ''?></td>
	<td><?=isset($sr['refund_transaction_id']) ? $sr['refund_transaction_id'] : ''?></td>
	<td><?=Helper_BSS_Normal::getIniOne('sales_refund_reason', 'value', $sr['reason'], 'name')?></td>
	<td><?=$sr['notes']?></td>
	<td><?=Helper_BSS_Normal::getIniOne('sales_order_shipping_status', 'value', $sr['shipping_status'], 'name')?></td>
	<td>
		<?if ($sr['status'] == Q::ini('custom_flag/sales_refund_status/new/value')):?>
		<a class="edit" href="<?=url('Finance::Business/RefundEdit', array('id' => $sr['id']))?>">修改</a>
		<a class="addrefund_click">退款</a>
		<?else:?><font color="#aaaaaa">已退</font>
		<?endif;?>
		<input type="hidden" value="<?=$sr['id']?>" />
		<input type="hidden" value="<?=$sr['refund_transaction_id']?>" />
	</td>
</tr>
<?endforeach;?>
</table>
<div id="dialog_refund_transaction_id" title="退款审核">
<form method="post" action="<?=url('Finance::Business/RefundAudit')?>">
<table class="form_table">
<tr>
	<th>退款交易号</th>
	<td>
		<input type="hidden" name="ids" id="refund_transaction_ids" />
		<input type="text" name="refund_transaction_id" id="refund_value" size="20" />
	</td>
</tr>
<tr>
	<th>退款日期</th>
	<td><input type="text" name="refund_time" class="datepicker" value="<?=date('Y-m-d', CURRENT_TIMESTAMP)?>" /></td>
</tr>
<tr>
	<th></th>
	<td><input type="submit" value="确认" class="button" /></td>
</tr>
</table>
</form>
</div>
<div id="dialog_refund_audit_ids" title="批量退款审核">
<form method="post" action="<?=url('Finance::Business/RefundAudit')?>">
<table class="form_table">
<tr>
	<th>退款日期</th>
	<td>
		<input type="text" name="refund_time" class="datepicker" value="<?=date('Y-m-d', CURRENT_TIMESTAMP)?>" />
		<input type="hidden" name="ids" id="ids" />
	</td>
</tr>
<tr>
	<th></th>
	<td><input type="submit" value="确认" class="button" /></td>
</tr>
</table>
</form>
</div>
<?=$page?>
<label><input type="checkbox" id="check_all" /> 全选</label>
<input type="button" class="button" id="audit_btn" value="批量审核" /> |
<a class="bulkedit" href="<?=url('Finance::Business/RefundBulkEdit') ?>"><input type="button" class="button" value="批量修改"/></a> |
<a class="detect" href="<?=url('Finance::Business/RefundDetect', array('url_arr' => serialize($url_arr))) ?>"><input type="button" class="button" value="检测"/></a>
搜索条件退款总额：
<?$currency = array();?>
<?foreach ($currency_code as $k => $c):?>
<?if (!empty($c)):?>
<?$currency[] = '<strong>' . $k . '</strong>' . sprintf("%.2f", $c);?>
<?endif;?>
<?endforeach;?>
<?=implode(' + ', $currency)?> = <strong>RMB</strong><?=$RMB;?>
<?php $this->_endblock(); ?>